package test_junit_merchant.ManageMerchant;


import org.openqa.selenium.By;
import util.BaseDriver;


import java.util.Random;
import java.util.UUID;

public class AddEmployee extends BaseDriver {

    private AddEmployee(){}

    private static  AddEmployee instance=new AddEmployee();

    public static AddEmployee getInstance(){

        return instance;
    }


    private static String phone="156";
    //生成随机工号
    private String employeenNumber= UUID.randomUUID().toString().substring(10);


    //切换菜单到商户管理->人力资源->员工管理
    public void switchMenu() throws InterruptedException {

        driver.findElement(By.cssSelector("span.nav-label")).click();
        Thread.sleep(500);
        driver.findElement(By.linkText("人力资源")).click();
        driver.findElement(By.linkText("员工管理")).click();


    }

    //增加员工
    public void addEmployee() throws InterruptedException {

        Thread.sleep(1000);
        driver=driver.switchTo().frame(2);

        //生成随机电话号码
        Random random=new Random();
        int i=8;
        while (i-->0){
            phone+=random.nextInt(10)+"";
        }

        Thread.sleep(1000);
        driver.findElement(By.cssSelector("button.btn.btn-sm.btn-outline.btn-primary")).click();
        Thread.sleep(2000);
        driver=driver.switchTo().frame(0);
        driver.findElement(By.id("employeeNo")).click();
        driver.findElement(By.id("employeeNo")).clear();
        driver.findElement(By.id("employeeNo")).sendKeys(employeenNumber);
        driver.findElement(By.id("phone")).click();
        driver.findElement(By.id("phone")).clear();
        driver.findElement(By.id("phone")).sendKeys(phone);
        driver.findElement(By.id("realName")).click();
        driver.findElement(By.id("realName")).clear();
        driver.findElement(By.id("realName")).sendKeys("iii");
        driver.findElement(By.cssSelector("button.btn.btn-primary")).click();
        driver=driver.switchTo().parentFrame();
        Thread.sleep(2000);
        driver=driver.switchTo().frame(1);
        driver.findElement(By.name("btSelectItem")).click();
        driver=driver.switchTo().parentFrame();
        driver.findElement(By.cssSelector("#layui-layer2 > div.layui-layer-btn > a.layui-layer-btn0")).click();
        driver=driver.switchTo().frame(0);
        driver.findElement(By.id("idcard")).click();
        driver.findElement(By.id("idcard")).clear();
        driver.findElement(By.id("idcard")).sendKeys("450902199609282954");
        driver.findElement(By.id("height")).click();
        driver.findElement(By.id("height")).clear();
        driver.findElement(By.id("height")).sendKeys("173");
        driver.findElement(By.id("weight")).click();
        driver.findElement(By.id("weight")).clear();
        driver.findElement(By.id("weight")).sendKeys("65");
        driver.findElement(By.id("shoeSize")).click();
        driver.findElement(By.id("shoeSize")).clear();
        driver.findElement(By.id("shoeSize")).sendKeys("37");
        driver.findElement(By.id("salary")).click();
        driver.findElement(By.id("salary")).clear();
        driver.findElement(By.id("salary")).sendKeys("1000");
        driver.findElement(By.id("commission")).click();
        driver.findElement(By.id("commission")).clear();
        driver.findElement(By.id("commission")).sendKeys("10");
        driver.findElement(By.id("entryTime")).click();
        driver.findElement(By.xpath("//table[@id='laydate_table']/tbody/tr/td[3]")).click();
        driver=driver.switchTo().parentFrame();
        driver.findElement(By.linkText("确定")).click();
        Thread.sleep(1000);
        driver.findElement(By.linkText("取消")).click();
    }





}
